import { axios } from '@/utils/request'
import signMd5Utils from '@/utils/encryption/signMd5Utils'
import { getAction, postAction, postFormData} from '@/api/manage'
const operate = '/jic-backend-duty/duty/'

const baseURL  = window._CONFIG['domianURL']  || '/jeecg-boot'
export const getClear = params => getAction(operate + 'integral/get', params)
export const editClear = params => getAction(operate + 'integral/delete', params)

// 退券
export const refundVoucher = params => getFormDataAction('/jic-backend-duty/duty/voucher/restore',params)
export const getList = params => getAction(operate + 'voucher/list/vouchers', params)
export const refundIntegral = params => postFormData(operate + `voucher/updateCouponStatus`,params)
export const asyncVip = params => postAction(operate + 'syncMemberInfo?' + `cno=${params.cno}&weid=${params.weid}`,params)
function verifyUrl(url) {
  // console.log('xxxxx********', url)
  const arr = url.split('/')
  if (arr.includes('sys') || arr.includes('online')) {
    if (arr.includes('jnby-boot')) {
      // /jnby-boot/sys/xxx
      const tmpUrl = url.split('/jnby-boot')
      return '/api/gateway/jnby-authority' + tmpUrl[1]
    } else {
      return '/api/gateway/jnby-authority' + (url.indexOf('/') == 0 ? url : '/' + url);
    }
  }

  // console.log('====verifyUrl')
  if (arr.includes('gateway') && arr.includes('api')) {
    return url
  }

  return '/api/gateway' + (url.indexOf('/') == 0 ? url : '/' + url);

}
// export const 
export function getFormDataAction(url, parameter) {
    let sign = signMd5Utils.getSign(url, parameter);
    //将签名和时间戳，添加在请求接口 Header
    let signHeader = { "X-Sign": sign, 'Content-Type': 'application/x-www-form-urlencoded', "X-TIMESTAMP": signMd5Utils.getDateTimeToString() };
    // console.log(url)
    url = verifyUrl(url)
    return axios({
      url: url,
      method: 'get',
      params: parameter,
      headers: signHeader
    })
  }
  export const queryReason = params => postFormData('/jic-backend-platform/platform/vou/not-avail/reason',params)